﻿using SUNRPA.CONTROLS.IMPL.domain.attrubutes;

namespace SUNRPA.CONTROLS.IMPL.domain.flowRunningVar {
    [ClassInfo("字典")]
    public class DictModel<K,V>:RPAVariable {
        private Dictionary<K,V> dictValue;

        public Dictionary<K,V> DictValue { 
            get { return dictValue; }
            set { dictValue = value; }
        }

        public DictModel(string name, Dictionary<K,V> dictValue) { 
            VarName = name;
            DictValue = dictValue;
        }

        public V? this[K key] { 
            get {
                if(dictValue.TryGetValue(key, out V value)) { 
                    return value;
                } else { 
                    return default;
                }
            }
            set { dictValue[key] = value; }
        }
        [VariableMemberInfo("转成字符串")]
        public override string ToString() { 
            return dictValue.ToString();
        }
    }
}
